using System;
using System.Threading;
using System.Threading.Tasks;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Ddl;
using Me.Prettyprint.Hector.Api.Factory;
using Me.Prettyprint.Hector.Api.Locking;

namespace Me.Prettyprint.Cassandra.Locking
{
	public class HLockImpl : HLock
	{
        public HLockImpl(string lockPath, string lockId)
        {
            Path = lockPath;
            LockId = lockId;
        }
        virtual public string Path
		{
			get;
			set;
		}
		virtual public string LockId
		{
			get;
			set;
		}
		virtual public HLockObserver Observer
		{
			get;
			set;
		}
		virtual public bool IsAcquired
        {
            get;
            set;
        }
        public Task<string> HeartBeat
        {
            get;
            set;
        }
        public async Task<string> GetHeartBeat()
        {
            return await HeartBeat;
        }
		public override int GetHashCode()
		{
			int prime = 31;
			int result = 1;
			result = prime * result + ((LockId == null)?0:LockId.GetHashCode());
			result = prime * result + ((Path == null)?0:Path.GetHashCode());
			return result;
		}
		public override bool Equals(object obj)
		{
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (GetType() != obj.GetType())
				return false;
			HLockImpl other = (HLockImpl) obj;
			if (LockId == null)
			{
				if (other.LockId != null)
					return false;
			}
			else if (!LockId.Equals(other.LockId))
				return false;
			if (Path == null)
			{
				if (other.Path != null)
					return false;
			}
			else if (!Path.Equals(other.Path))
				return false;
			return true;
		}
		
		public override string ToString()
		{
			return "HLockImpl [lockPath=" + Path + ", lockId=" + LockId + ", acquired=" + IsAcquired + "]";
		}
	}
}